﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

namespace lcs.Web.SysMan
{
    public partial class ListUserInfo : Web.Admin.BasePage
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                if (Session["login"] != null)
                {
                    DataSet ds = Session["login"] as DataSet;

                    int roles_id = Convert.ToInt32(ds.Tables[0].Rows[0]["roles_id"].ToString());
                    int user_id = Convert.ToInt32(ds.Tables[0].Rows[0]["user_id"].ToString());

                    if (roles_id == 1)//管理员
                    {
                        Bind();
                       
                    }
                    else
                    {
                        Response.Redirect("../default.aspx");
                    }


                }
            }
        }

        private void Bind()
        {
            this.GridView1.DataSource = new lcs.BLL.user().GetUserRoles("");
            this.DataBind();
           
        }

        protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e)
        {
            if (e.CommandName == "check")
            {
                if (e.CommandArgument != null)
                {
                    string user_id = e.CommandArgument.ToString();

                    Response.Redirect("AddUser.aspx?user_id="+user_id);
                }
            }
            if (e.CommandName == "lbn_del")
            {
                if (e.CommandArgument != null)
                {
                    string user_id = e.CommandArgument.ToString();

                    lcs.BLL.user um = new BLL.user();

                    if (um.Delete(int.Parse(user_id)))
                    {
                        Bind();
                    }
                }
            }
        }
    }
}